package com.wyl.aop.jdk.aop;

import com.wyl.aop.jdk.service.Star;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class StarProxy implements InvocationHandler {

    private Object star;

    public StarProxy(Star star){
        this.star = star;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("经纪人收钱");
        Object result = method.invoke(star, args);
        this.clean();
        return result;
    }

    // 生成代理类
    public Object CreatProxyedObj() {
        Object invocationHandlerProxy = Proxy.newProxyInstance(star.getClass().getClassLoader(), star.getClass().getInterfaces(), this);
        return invocationHandlerProxy;
    }

    public void clean(){
        System.out.println("经纪人请人搞卫生");
    }
}